package br.com.SGF.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.SGF.dao.SenhaDAO;
import br.com.SGF.domain.SenhaDomain;



@FacesConverter("senhaConverter")
public class SenhaConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent component, String valor) {
		try{
			int codigo = Integer.parseInt(valor);
			SenhaDAO fabdao = new SenhaDAO();
			SenhaDomain fab = fabdao.obterCodigo(codigo);
			return fab;
		}catch(RuntimeException e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent component, Object objeto) {
		try{
			SenhaDomain fab = (SenhaDomain) objeto;
			System.out.println(fab.getCodigo());
			Integer codigo = fab.getCodigo();
		
			return codigo.toString();
		}catch(RuntimeException e){
			e.printStackTrace();
			return null;
		}
	}

}
